<tagLib name="lbase"/>
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>微信公众平台营销管理系统</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
    <include file='Public:header' />
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="__ROOT__/public/js/html5shiv.js"></script>
    <![endif]-->
</head>

<body>
    <!--nav-->
<include file='Public:nav' />
<div class="container">
    <!--            <ul class="breadcrumb">
                    <li><a href="#">首页</a> <span class="divider">/</span></li>
                    <li><a href="#">Library</a> <span class="divider">/</span></li>
                    <li class="active">Data</li>
                </ul>-->
    <div class="page-header"><h4>文本指令编辑</h4></div>

    <!--<p class="view"><b>功能：</b>管理&nbsp;|&nbsp;添加|&nbsp;添加|&nbsp;添加|&nbsp;添加|&nbsp;添加</p>-->
    <div class="row">
        <div class="span12">
            <div class="pull-left">
                <a href="{:U('/'.$module_name)}" class="btn btn-primary">列 表</a>&nbsp;&nbsp;
                <a class="btn btn-primary" href="{$pre_url}">返 回</a>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="span12" style="margin-top:10px;">
            <form class="form-horizontal" method="post">
                <fieldset>
                    <div id="legend" class="">
                        <legend class=""></legend>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="input01">指令</label>
                        <div class="controls">
                            <input type="text" name="code" placeholder="文本指令" value="{$info.code}" class="input-xlarge">
                            <p class='help-block'>用来识别用户回复的文本指令</p>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label" for="input01">菜单响应KEY</label>
                        <div class="controls">
                            <input type="text" name="menu_key" placeholder="菜单响应KEY" value="{$info.menu_key}" class="input-xlarge">
                            <p class='help-block'>用来识别用户点击的自定义菜单按钮，如不需要关联菜单请留空</p>
                        </div>
                    </div>


                    <div class="control-group">
                        <!-- Select Basic -->
                        <label class="control-label">回复类型</label>
                        <div class="controls">
                            <select class="input-xlarge" name="msg_type">
                                <option value="1"<php>if($info['msg_type']==1) echo ' selected="selected"';</php>>单条文本</option>
                                <option value="2"<php>if($info['msg_type']==2) echo ' selected="selected"';</php>>单条图文</option>
                                <option value="3"<php>if($info['msg_type']==3) echo ' selected="selected"';</php>>图文列表</option>
                            </select>
                        </div>
                    </div>
                    <div class="control-group">

                        <!-- Text input-->
                        <label class="control-label" for="input01">标题</label>
                        <div class="controls">
                            <input type="text" name="title" placeholder="标题" value="{$info.title}" class="input-xlarge">
                            <p class="help-block">当为单条文本时，不在用户微信显示，只对管理员有标识作用</p>
                        </div>
                    </div>
                    <div class="control-group">
                        <!-- Textarea -->
                        <label class="control-label">描述</label>
                        <div class="controls">
                            <div class="textarea">
                                <textarea name="description">{$info.description}</textarea>
                            </div>
                        </div>
                    </div>

                    <div class="control-group"<php>if($info['msg_type']!=2 && $info['msg_type']!=3)echo ' style="display:none;"';</php>>
                        <!-- Text input-->
                        <label class="control-label" for="input01">点击链接</label>
                        <div class="controls">
                            <input type="text" name="click_url" value="{$info.click_url}" placeholder="点击的链接地址" class="input-xlarge">
                            <p class="help-block">完整的url链接，如为空，则自动生成文章内容页面</p>
                        </div>
                    </div>
                    <div class="control-group" id="pic_upload"<php>if($info['msg_type']!=2 && $info['msg_type']!=3)echo ' style="display:none;"';</php>>
                        <label class="control-label">封面</label>
                        <!-- Button -->
                        <div class="controls">
                            <lbase:imgUpload name='imgupload' value="{$info.pic_url_small}" />
                            <p class="help-block">图片尺寸：640*320</p>
                        </div>
                    </div>


                    <div class="control-group">
                        <label class="control-label">状态</label>
                        <div class="controls">
                            <!-- Inline Radios -->
                            <label class="radio inline">
                                <input type="radio" value="1" name="status"<php>if($info['status']==1) echo ' checked="checked"';</php>>
                                启用
                            </label>
                            <label class="radio inline">
                                <input type="radio" value="0" name="status"<php>if($info['status']==0) echo ' checked="checked"';</php>>
                                禁用
                            </label>
                        </div>
                    </div><div class="control-group">

                        <!-- Textarea -->
                        <label class="control-label">内容</label>
                        <div class="controls">
                            <div class="textarea">
                                <lbase:editor name="contents" content='{$info.contents}' type="editor" width="70%" />
                            </div>
                            <p class="help-block">客户端显示的内容，当为单条文本时，请填写纯文本</p>
                        </div>
                    </div>


                    <div class="control-group"<php>if($info['msg_type']!=2 && $info['msg_type']!=3)echo ' style="display:none;"';</php>>
                        <!-- Select Basic -->
                        <label class="control-label">所属图文列表主题</label>
                        <div class="controls">
                            <select class="input-xlarge" name="main">
                                <option value="0"<php>if($info['main']==0) echo ' selected="selected"';</php>>顶级</option>
                                <foreach name="main_list" item="ml">
                                    <option value="{$ml.id}"<php>if($info['main']==$ml['id']) echo ' selected="selected"';</php>>{$ml.title}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>




                    <div class="control-group"<php>if($info['msg_type']!=3 || $info['main']==0) echo ' style="display:none;"';</php>>

                        <!-- Text input-->
                        <label class="control-label" for="input01">排序</label>
                        <div class="controls">
                            <input type="text" placeholder="排序" name="sort" value="{$info.sort}" class="input-xlarge">
                            <p class="help-block">图文列表的排序顺序</p>
                        </div>
                    </div>

                    <div class="control-group">

                        <!-- Textarea -->
                        <label class="control-label">备注</label>
                        <div class="controls">
                            <div class="textarea">
                                <textarea name="remark">{$info.remark}</textarea>
                            </div>
                        </div>
                        <div id='pop'></div>

                        <div class="form-actions">
                            <input type="hidden" name="id" value="{$info.id}">
                            <button type="button" class="btn btn-primary" id='save'>保 存</button>&nbsp;&nbsp;
                            <a class="btn" href="{$pre_url}">返 回</a>
                        </div>

                </fieldset>
            </form>
        </div>
    </div>

</div>
</div>

<include file='Public:footer' />
<script type="text/javascript">
                    $(function() {
                        $('[name=msg_type]').change(function() {
                            msg_type_change()
                        });

                        $('[name=main]').change(function() {
                            main_change()
                        });

                        function main_change() {
                            var id = $('[name=main]').val();
                            if (id == '0') {
                                $('[name=sort]').parent().parent().hide();
                            } else {
                                $('[name=sort]').parent().parent().show();
                            }
                        }

                        function msg_type_change() {
                            var value = $('[name=msg_type]').val();

                            switch (value) {
                                case "1":
                                    $('[name=click_url]').parent().parent().hide();
                                    $('#pic_upload').hide();
                                    $('[name=main]').parent().parent().hide();
                                    $('[name=sort]').parent().parent().hide();
                                    break;
                                case "2":
                                    $('[name=click_url]').parent().parent().show();
                                    $('#pic_upload').show();
                                    $('[name=main]').parent().parent().hide();
                                    $('[name=sort]').parent().parent().hide();
                                    break;
                                case "3":
                                    $('[name=click_url]').parent().parent().show();
                                    $('#pic_upload').show();
                                    $('[name=main]').parent().parent().show();
//                $('[name=sort]').parent().parent().hide();
                                    break;
                            }
                        }

                        $('#save').click(function() {
                            contents_editor.sync();
                            var data = $('form').serialize();
                            $.ajax({
                                type: "POST",
                                url: app_url + "/" + module_name + "/update",
                                data: data,
                                timeout: 5000,
                                dataType: 'json',
                                cache: false,
                                success: function(data) {
                                    success(data);
                                },
                                error: function() {
                                    error();
                                }
                            });

                        });

                        $('#pop').ajaxStart(function() {
                            $('#pop').html('<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>数据请求中，请稍候...</div>')
                                    .fadeIn("slow");
                        });

                        function success(data) {
                            if (data.data == 1) {
                                $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>信息修改成功！</div>')
                                        .fadeIn("slow")
                                        .fadeOut(5000);
                            } else {
                                $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>信息修改失败或者信息并无改变！</div>')
                                        .fadeIn("slow")
                                        .fadeOut(5000);
                            }
                        }

                        function error() {
                            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>远程服务器请求失败！</div>')
                                    .fadeIn("slow")
                                    .fadeOut(5000);
                        }
                    });
</script>
</body>
</html>
